#include<iostream>
#include<vector>
#include<algorithm>
using namespace std ; 
typedef long long ll ; 
ll rd(){
	ll a = 0 ; 
	scanf("%lld",&a);
	return a ; 
} 
const ll LEN = 1e7+10 ; 
ll is[LEN] = {0} ; 
int main(){
	//n代表星星的亮度，w代表窗户的宽度 
	ll n = rd() , w = rd() ; 
	
	//最后一颗星星的坐标 
	ll endx = 0 ; 
	//输入数据并构建差分数组 
	for(int i = 0 ; i < n ; i++){
		//x代表星星的坐标 ，b代表星星的亮度 
		ll x = rd() , b = rd() ;
		ll l = max(x-w,0ll) ; 
		ll r = min(LEN-1 , x) ; 
		is[l] += b ; 
		is[r] -= b ; 
		
		endx = max(x,endx);
	}
	//求和，并获取最大值 
	ll sum = 0 , ans = 0 ; 
	for(int i = 0 ; i <= endx;i++){
		sum += is[i] ; 
		ans = max(sum ,ans) ; 	
	} 
	printf("%lld",ans) ;  
	
	return 0 ; 
}